const minHeight = 150;
const maxHeight = 220;

export const getHeightList = ({ hasEmpty = true } = {}) => {
  const heightList = [];
  if (hasEmpty) {
    heightList.push('不限');
  }
  console.log(hasEmpty, 4444444)
  for (let i=minHeight; i <= maxHeight; i++)  {
    heightList.push(i);
  }
  return heightList
}

export const getHeightRange = ({ hasEmpty = true, multiple = false } = {}) => {
  if (multiple) {
    return [getHeightList({ hasEmpty }), '至', getHeightList({ hasEmpty })]
  }
  return getHeightList({ hasEmpty });
}

export const getHeightIndexs = ({ hasEmpty = true, multiple=true, value } = {}) => {
  if (!value) {
    return multiple ? [0, 0, 0] : 0
  }

  if (Array.isArray(value) && value.length == 0) {
    return multiple ? [0, 0, 0] : 0
  }
  const ageList = getHeightList({ hasEmpty });
  if (Array.isArray(value)) {
    const [minValue, maxValue] = value || [];
    let minIndex = ageList.findIndex(item => item == minValue);
    minIndex = minIndex == -1 ? 0 : minIndex
    let maxIndex = ageList.findIndex(item => item == maxValue);
    maxIndex = maxIndex == -1 ? 0 : maxIndex
    return [minIndex, 0, maxIndex];
  } else {
    const index = ageList.findIndex(item => item == value);
    return index
  }
}

export const getHeightValueByIndex = ({ hasEmpty = true, index, multiple=true } = {}) => {
  const ageList = getHeightList({ hasEmpty });
  if (multiple) {
    let minValue = parseInt(ageList[index[0]]);
    let maxValue = parseInt(ageList[index[2]]);
    let result;
    if (isNaN(minValue) && isNaN(maxValue)) {
      result = [null, null];
    } else if (isNaN(minValue)){
      result = [null, maxValue]
    } else if (isNaN(maxValue)) {
      result = [minValue, null]
    } else {
      if (minValue < maxValue) {
        result = [minValue, maxValue]
      } else {
        result = [maxValue, minValue]
      }
    }

    return result;
  } else {
    let value = parseInt(ageList[index]);
    return isNaN(value) ? null : value
  }
}

export const getHeightText = (min, max) => {
  if (!min && !max) {
    return
  }
  if (min && !max) {
    return `${min}以上`
  }
  if (max && !min) {
    return `${max}以内`
  }

  return `${min}-${max}cm`
}

// const indexs = getAgeIndexs({ value: [1991, 1996], })
// const ageRange = getAgeRange({ multiple: true })
// const ageValue = getAgeValueByIndex({ hasEmpty: true, index: [1, 0, 2], multiple: true });